﻿// See https://aka.ms/new-console-template for more information

Console.WriteLine("开始处理...");

Task.Run(OnExecute);

Console.WriteLine("处理完成");
Console.Read();

static void OnExecute() {
    var users = new Users();
    users.Add(new User());
    users.Add(new User());

    users.Reset();

    var users2 = users.GetUsers();
    users2[0].Name = "Test";
}

public class Users {
    private List<User> users = new List<User>();

    public IUser[] GetUsers() => users.ToArray();

    public void Reset() {
        foreach (User user in users) {
            user.Reset();
        }
    }

    public void Add(User user) { users.Add(user); }
}

public interface IUser {
    string Name { get; set; }
}

public class User : IUser {
    public string Name { get; set; } = string.Empty;

    public void Reset() => Name = "test1";
}

//static void Test1()
//{
//    using (var user = new User())
//    {
//        //...
//    }
//}

//static void Test2()
//{
//    using var user2 = new User();
//}


//public class User : IDisposable
//{
//    public const string TEST_USER = "1";
//    public int Id { get; set; }
//    public void Dispose()
//    {
//        throw new NotImplementedException();
//    }
//}

